package com.briup.smart.mapper;

import com.briup.smart.bean.User;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface UserMapper {
    @Delete("delete from es_user where id = #{id}")
    public void deleteById(Integer id);

    @Insert("insert into es_user(username,password,phone,gender,birthday,register_time) values (#{username},#{password},#{phone},#{gender},#{birthday},#{registerTime})")
    void insert(User user);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into `es_user`(username,password,phone,gender,birthday,register_time) " + "values (#{username},#{password},#{phone},#{gender},#{birthday},#{registerTime})")
    public void insert_id(User user);

    @Update("update es_user set username= #{username},phone = #{phone},avatar = #{avatar},gender = #{gender},status = #{status},birthday = #{birthday} where id = #{id}")
    public void update(User user);

    //根据id查询用户信息
    @Results({@Result(column = "register_time", property = "registerTime")})
    @Select("""
            select id,username,password,
            phone,avatar,gender,
            status,birthday,register_time
            from es_user
            where id=#{id}
            """)
    public User getById(Integer id);

    //条件查询
    @Select("""
            select id,username,password,phone,avatar,gender,status,birthday
            from es_user
            where username like concat('%',#{name},'%')
            and status = #{status}
            and register_time between #{startTime} and #{endTime}
            order by register_time desc
            """)
    List<User> getByCondition(String username, String status, LocalDate startTime,LocalDate endTime);
}
